package com.example.chapter3.homework;


import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.example.chapter3.homework.PageFragment.*;

import java.util.Objects;


public class PlaceholderFragment extends Fragment {


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        // TODO ex3-3: 修改 fragment_placeholder，添加 loading 控件和列表视图控件
        return inflater.inflate(R.layout.fragment_placeholder, container, false);
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
        super.onActivityCreated(savedInstanceState);

        // 初始加载动画
        FragmentManager fragmentManager1=getFragmentManager();
        mPageFrament4Lottie fra=new mPageFrament4Lottie();
        FragmentTransaction transaction=fragmentManager1.beginTransaction();
        transaction.replace(R.id.placeholder,fra);
        transaction.commit();

        // 加载列表，替换动画
        Objects.requireNonNull(getView()).postDelayed(new Runnable() {
            @Override
            public void run() {
                // 这里会在 5s 后执行
                // TODO ex3-4：实现动画，将 lottie 控件淡出，列表数据淡入
                FragmentManager fragmentManager2=getFragmentManager();
                mPageFrament4List frament4List = new mPageFrament4List();

                // 执行事务
                FragmentTransaction transaction2=fragmentManager2.beginTransaction();
                // 设置过度效果
                transaction2.setCustomAnimations(R.anim.in,R.anim.out);
                transaction2.replace(R.id.placeholder,frament4List);
                transaction2.commit();


            }
        }, 5000);
    }
}
